/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaoshujin
 * Date: 2011-9-1 下午04:09:36
 */
package com.xml;

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

import com.util.ConstUtil;

/**
 * 通过URL获取返回信息
 * @author zhaoshujin
 * 
 */
public class UrlXml {

	private void getRemoteData(String remoteUrl, String fileName) {
		try {
			URL url = new URL(remoteUrl);
			URLConnection con = url.openConnection();
			
			//从远程连接获取输入流
			BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream(), ConstUtil.DEFAULT_ENCODE));

			// 输出到文件
			FileOutputStream os = new FileOutputStream(fileName, false);

			String line = null;
			while ((line = in.readLine()) != null) {
				os.write((line + "\r\n").getBytes());
				os.flush();
			}

			os.close();

		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		
		long start = System.currentTimeMillis();

		UrlXml ux = new UrlXml();

		String fileName = "F:\\MYDOCUMENT\\_TEMP\\FunctionParameterInfo.xml";
		//String url = "http://10.0.2.215/ccxe/services/ccxWebService?wsdl";
		//String url = "http://119.254.64.177:8888/ccxe/services/ccxWebService?wsdl";
		String url = "http://10.0.2.136:8180/ccxe/services/ccxWebService/getAllFunctionParameterInfo";

		ux.getRemoteData(url, fileName);
		
		long end = System.currentTimeMillis();

		System.out.println("OVER:"+(end-start));

	}

}
